package com.inno.auth.controller.error;

import com.inno.auth.common.entity.CommonReturnType;
import com.inno.auth.common.enums.ResultCodeEnum;
import com.inno.auth.common.error.AuthException;
import feign.RetryableException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class AuthExceptionHandler {
    @ExceptionHandler(AuthException.class)
    public CommonReturnType<Object> handleAuthException(AuthException e) {
        log.error("用户模块异常:", e);
        return CommonReturnType.fail(e.getMessage());
    }
    @ExceptionHandler(NullPointerException.class)
    public CommonReturnType<Object> handle(NullPointerException e) {
        log.error("NullPointerException:", e);
        return CommonReturnType.fail(ResultCodeEnum.FAIL.getCode(), e.getMessage());
    }
    @ExceptionHandler(IllegalArgumentException.class)
    public CommonReturnType<Object> handle(IllegalArgumentException e) {
        log.error("IllegalArgumentException:", e);
        return CommonReturnType.fail(ResultCodeEnum.FAIL.getCode(), e.getMessage());
    }

    @ExceptionHandler(RetryableException.class)
    public CommonReturnType<Object> handle(RetryableException e) {
        log.error("RetryableException:", e);
        return CommonReturnType.fail(ResultCodeEnum.FAIL.getCode(), "请求超时,请刷新重试");
    }

    @ExceptionHandler(Exception.class)
    public CommonReturnType<Object> handle(Exception e) {
        log.error("系统异常:", e);
        return CommonReturnType.fail(ResultCodeEnum.FAIL.getCode(), "系统繁忙");
    }
}
